import threading
import redis

# 连接到 Redis 服务器
client = redis.Redis(host='localhost', port=6379, db=0)

# 设置初始值
client.set('counter', 600)

# 定义一个函数来执行 DECR 操作


def decr_counter():
    for _ in range(200):
        res = client.decr('counter')
        print(res)


# 创建三个线程
threads = []
for _ in range(3):
    t = threading.Thread(target=decr_counter)
    threads.append(t)
    t.start()

# 等待所有线程完成
for t in threads:
    t.join()

# 获取最终值
final_value = client.get('counter')
print(final_value)  # 输出 b'0'
